﻿Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Xml


Public Class SiteSettings

    Private Const XMLPath As String = "~/App_Data/SiteSettings.xml"

#Region " Public Properties"

    Public Shared Property RequireLogin As Boolean
    Public Shared Property AllowManualRegistration As Boolean
    Public Shared Property SiteMessage As String
    Public Shared Property OnlyAdminsCanEdit As Boolean
    Public Shared Property AutoApproveUsers As Boolean
    Public Shared Property SiteFromEmail As String
    Public Shared Property SiteContactEmail As String
    Public Shared Property SiteEmailServer As String
    Public Shared Property SiteEmailUsername As String
    Public Shared Property SiteEmailPassword As String

#End Region


    Public Shared Sub FillSiteSettings()
        Dim xdoc As New XmlDocument
        xdoc.Load(HttpContext.Current.Server.MapPath(XMLPath))
        Dim x As XmlNode = xdoc("SiteSettings")
        _RequireLogin = CBool(x.SelectSingleNode("RequireLogin").InnerText)
        _AllowManualRegistration = CBool(x.SelectSingleNode("AllowManualRegistration").InnerText)
        _SiteMessage = x.SelectSingleNode("SiteMessage").InnerText
        _OnlyAdminsCanEdit = CBool(x.SelectSingleNode("OnlyAdminsCanEdit").InnerText)
        _AutoApproveUsers = CBool(x.SelectSingleNode("AutoApproveUsers").InnerText)
        _SiteFromEmail = x.SelectSingleNode("SiteFromEmail").InnerText
        _SiteContactEmail = x.SelectSingleNode("SiteContactEmail").InnerText
        _SiteEmailServer = x.SelectSingleNode("SiteEmailServer").InnerText
        _SiteEmailUsername = x.SelectSingleNode("SiteEmailUsername").InnerText
        _SiteEmailPassword = x.SelectSingleNode("SiteEmailPassword").InnerText

    End Sub
    Public Shared Sub Save()
        Dim xdoc As New XmlDocument
        xdoc.Load(HttpContext.Current.Server.MapPath(XMLPath))
        Dim x As XmlNode = xdoc("SiteSettings")
        x.SelectSingleNode("RequireLogin").InnerText = RequireLogin
        x.SelectSingleNode("AllowManualRegistration").InnerText = AllowManualRegistration
        x.SelectSingleNode("SiteMessage").InnerText = SiteMessage
        x.SelectSingleNode("OnlyAdminsCanEdit").InnerText = OnlyAdminsCanEdit
        x.SelectSingleNode("AutoApproveUsers").InnerText = AutoApproveUsers
        x.SelectSingleNode("SiteFromEmail").InnerText = SiteFromEmail
        x.SelectSingleNode("SiteContactEmail").InnerText = SiteContactEmail
        x.SelectSingleNode("SiteEmailServer").InnerText = SiteEmailServer
        x.SelectSingleNode("SiteEmailUsername").InnerText = SiteEmailUsername
        x.SelectSingleNode("SiteEmailPassword").InnerText = SiteEmailPassword

        xdoc.Save(HttpContext.Current.Server.MapPath(XMLPath))
        FillSiteSettings()
    End Sub

End Class
